<?php
/**
* //////////////////////////////////////////////////
* auto execute , for initialize config variable
* this function auto call every page has been fetch
*/
function _autoexecute(){

}

function _checkParameter($params=NULL){
  
}

function VotePortal_ws_getProvinceList(){
  Loader::loadClass('VoteDataCenterReader', "modules/VotePortal/pnincludes");
  $getter = new VoteDataCenterReader();
  
  if(FormUtil::getPassedValue ('list', FALSE, 'REQUEST')){
      $params['list'] = FormUtil::getPassedValue ('list', FALSE, 'REQUEST');
  }

  $objDataArray = $getter->getProvinceList($params);

  header("Content-type: text/xml");
  $xml = new DOMDocument("1.0", "utf-8" );
  $xml->preserveWhiteSpace = false; 
  $xml->formatOutput = true;
  
  $xmlDatas = $xml->createElement("datas");
  
  if(empty($objDataArray))
  {
    $xmlChild = $xml->createElement("data");
    $xmlChild->setAttribute("id",0);
    
    $xmlTitle = $xml->createElement("title","ไม่มีข้อมูล");
    $xmlChild->appendChild($xmlTitle);
    
    $xmlDes = $xml->createElement("description",getter->getErrorMessage());
    $xmlChild->appendChild($xmlDes);
    
    $xmlDatas->appendChild($xmlChild);
    $xml->appendChild($xmlDatas);
  
    print $xml->saveXML();
    pnShutDown();
  }

  
  foreach($objDataArray as $val)
  {
    
    $xmlChild = $xml->createElement("data");
    
    $xmlChild->setAttribute("id","pv".sprintf("%06d",$val['id']));

    $xmlTitle = $xml->createElement("title","จ.".$val['name']);
    $xmlChild->appendChild($xmlTitle);
    
    $xmlCountry = $xml->createElement("country","ประเทศไทย");
    $xmlChild->appendChild($xmlCountry);
    
    $xmlLogo = $xml->createElement("logo",htmlentities(str_replace(basename($_SERVER['PHP_SELF']),"","http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']).'modules/VoteThailandPoll/pnimages/province/'.$val['id'].".png"));
    $xmlChild->appendChild($xmlLogo);
    
    $xmlPop = $xml->createElement("population","300000");
    $xmlChild->appendChild($xmlPop);
    
    $xmlLat = $xml->createElement("latitude",$val['latitude']);
    $xmlChild->appendChild($xmlLat);
    
    $xmlLon = $xml->createElement("longitude",$val['longitude']);
    $xmlChild->appendChild($xmlLon);
    
    $xmlSpan = $xml->createElement("span",0.4);
    $xmlChild->appendChild($xmlSpan);
    
    $xmlInfo = $xml->createElement("infopath",htmlentities(str_replace(basename($_SERVER['PHP_SELF']),"","http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']).'index.php?module=VoteThailandPoll&type=xml&func=province&pid='.$val['id']));
    $xmlChild->appendChild($xmlInfo);
    
    $xmlReport = $xml->createElement("reportpath",htmlentities(str_replace(basename($_SERVER['PHP_SELF']),"","http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']).'index.php?module=VoteThailandPoll&type=xml&func=report&pid='.$val['id']));
    $xmlChild->appendChild($xmlReport);
    
    $xmlCurrent = $xml->createElement("xmlcurrent",'http://www.phuketinnova.com/demo/gthai/pv00001.xml');
    $xmlChild->appendChild($xmlCurrent);
    
    $xmlPath = $xml->createElement("xmlpath",htmlentities(str_replace(basename($_SERVER['PHP_SELF']),"","http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']).'index.php?module=VoteThailandPoll&type=xml&func=district&pid='.$val['id']));
    $xmlChild->appendChild($xmlPath);
    
    $xmlUpdate = $xml->createElement("xmlupdate",'ProvinceData');
    $xmlChild->appendChild($xmlUpdate);
    
    $xmlDate = $xml->createElement("date",$val['lu_date']);
    $xmlChild->appendChild($xmlDate);
    
    $xmlDatas->appendChild($xmlChild);
  }

  $xml->appendChild($xmlDatas);
  
  
  print $xml->saveXML();
  pnShutDown();
}


?>